package com.zfx.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.factory.PasswordEncoderFactories;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;

/**
 * @description:
 * @author: zfx
 * @version: 1.0
 * @time: 2020-05-07 22:04
 * <p>
 * 修改历史：
 * 修改日期      修改人员    版本    内容
 * 2020-05-07   zfx       1.0
 */
//@Configuration
//@EnableWebSecurity
public class WebSecurityConfig {

    @Bean
    public UserDetailsService userDetailsService() {
        PasswordEncoder encoder = PasswordEncoderFactories.createDelegatingPasswordEncoder();
        InMemoryUserDetailsManager manager = new InMemoryUserDetailsManager();
        manager.createUser(User
                .withUsername("admin")
                .password("admin")
                .passwordEncoder(encoder::encode)
                .roles("")
                .build()
        );
        manager.createUser(User
                .withUsername("guest")
                .password("guest")
                .passwordEncoder(encoder::encode)
                .roles("")
                .build()
        );
        return manager;
    }
}
